home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / xmodem.doc < prev    next >
Text File  |  1985-06-03  |  8KB  |  183 lines

  1.  
  2.  
  3. MODEM PROTOCOL OVERVIEW  178 lines, 7.5K
  4.  
  5. 1/1/82 by Ward Christensen.  I will maintain a master copy of
  6. this.  Please pass on changes or suggestions via CBBS/Chicago
  7. at (312) 545-8086, or by voice at (312) 849-6279.
  8.  
  9. NOTE this does not include things which I am not familiar with,
  10. such as the CRC option implemented by John Mahr.
  11.  
  12. Last Rev: (none)
  13.  
  14. At the request of Rick Mallinak on behalf of the guys at
  15. Standard Oil with IBM P.C.s, as well as several previous
  16. requests, I finally decided to put my modem protocol into
  17. writing.  It had been previously formally published only in the
  18. AMRAD newsletter.
  19.  
  20.        Table of Contents
  21. 1. DEFINITIONS
  22. 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  23. 3. MESSAGE BLOCK LEVEL PROTOCOL
  24. 4. FILE LEVEL PROTOCOL
  25. 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  26. 6. PROGRAMMING TIPS.
  27.  
  28. -------- 1. DEFINITIONS.
  29. Name   Hex   ASCII  Ctrl+
  30. <soh>  01H    1     ^@
  31. <eot>  04H    4     ^D
  32. <ack>  05H    5     ^E
  33. <nak>  15H    21    ^U
  34. <can>   18H   24    ^X
  35.  
  36. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  37. Asynchronous, 8 data bits, no parity, one stop bit.
  38.  
  39.     The protocol imposes no restrictions on the contents of the
  40. data being transmitted.  No control characters are looked for
  41. in the 128-byte data messages.  Absolutely any kind of data may
  42. be sent - binary, ASCII, etc.  The protocol has not formally
  43. been adopted to a 7-bit environment for the transmission of
  44. ASCII-only (or unpacked-hex) data , although it could be simply
  45. by having both ends agree to AND the protocol-dependent data
  46. with 7F hex before validating it.  I specifically am referring
  47. to the checksum, and the block numbers and their ones-
  48. complement.
  49.     Those wishing to maintain compatibility of the CP/M file
  50. structure, i.e. to allow modemming ASCII files to or from CP/M
  51. systems should follow this data format:
  52.   * ASCII tabs used (09H); tabs set every 8.
  53.   * Lines terminated by CR/LF (0DH 0AH)
  54.   * End-of-file indicated by ^Z, 1AH.  (one or more)
  55.   * Data is variable length, i.e. should be considered a
  56.     continuous stream of data bytes, broken into 128-byte
  57.     chunks purely for the purpose of transmission.
  58.   * A CP/M "peculiarity": If the data ends exactly on a
  59.     128-byte boundary, i.e. CR in 127, and LF in 128, a
  60.     subsequent sector containing the ^Z EOF character(s)
  61.     is optional, but is preferred.  Some utilities or
  62.     user programs still do not handle EOF without ^Zs.
  63.   * The last block sent is no different from others, i.e.
  64.     there is no "short block".
  65.  
  66. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  67.  Each block of the transfer looks like:
  68. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  69.     in which:
  70. <SOH>       = 01 hex
  71. <blk #>     = binary number, starts at 01 increments by 1, and
  72.               wraps 0FFH to 00H (not to 01)
  73. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  74.               each bit complemented in the 8-bit block number.
  75.               Formally, this is the "ones complement".
  76. <cksum>     = the sum of the data bytes only.  Toss any carry.
  77.  
  78. -------- 4. FILE LEVEL PROTOCOL
  79.  
  80. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  81.  
  82.     All errors are retried 10 times.  For versions running with
  83. an operator (i.e. NOT with XMODEM), a message is typed after 10
  84. errors asking the operator whether to "retry or quit".
  85.     Some versions of the protocol use <can>, ASCII ^X, to
  86. cancel transmission.  This was never adopted as a standard, as
  87. having a single "abort" character makes the transmission
  88. susceptible to false termination due to an <ack> <nak> or <soh>
  89. being corrupted into a <can> and canceling transmission.
  90.     The protocol may be considered "receiver driven", that is,
  91. the sender need not automatically re-transmit, although it does
  92. in the current implementations.
  93.  
  94. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  95.     The receiver has a 10-second timeout.  It sends a <nak>
  96. every time it times out.  The receiver's first timeout, which
  97. sends a <nak>, signals the transmitter to start.  Optionally,
  98. the receiver could send a <nak> immediately, in case the sender
  99. was ready.  This would save the initial 10 second timeout.
  100. However, the receiver MUST continue to timeout every 10 seconds
  101. in case the sender wasn't ready.
  102.     Once into a receiving a block, the receiver goes into a
  103. one-second timeout for each character and the checksum.  If the
  104. receiver wishes to <nak> a block for any reason (invalid
  105. header, timeout receiving data), it must wait for the line to
  106. clear.  See "programming tips" for ideas
  107.     Synchronizing:  If a valid block number is received, it
  108. will be: 1) the expected one, in which case everything is fine;
  109. or 2) a repeat of the previously received block.  This should
  110. be considered OK, and only indicates that the receivers <ack>
  111. got glitched, and the sender re-transmitted; 3) any other block
  112. number indicates a fatal loss of synchronization, such as the
  113. rare case of the sender getting a line-glitch that looked like
  114. an <ack>.  Abort the transmission, sending a <can>
  115.  
  116. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  117.  
  118.     While waiting for transmission to begin, the sender has
  119. only a single very long timeout, say one minute.  In the
  120. current protocol, the sender has a 10 second timeout before
  121. retrying.  I suggest NOT doing this, and letting the protocol
  122. be completely receiver-driven.  This will be compatible with
  123. existing programs.
  124.     When the sender has no more data, it sends an <eot>, and
  125. awaits an <ack>, resending the <eot> if it doesn't get one.
  126. Again, the protocol could be receiver-driven, with the sender
  127. only having the high-level 1-minute timeout to abort.
  128.  
  129.  
  130. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  131.  
  132. Here is a sample of the data flow, sending a 3-block message.
  133. It includes the two most common line hits - a garbaged block,
  134. and an <ack> reply getting garbaged.  <xx> represents the
  135. checksum byte.
  136.  
  137. SENDER                                 RECEIVER
  138.                                times out after 10 seconds,
  139.                        <---            <nak>
  140. <soh> 01 FE -data- <xx>        --->
  141.                        <---            <ack>
  142. <soh> 02 FD -data- xx  --->    (data gets line hit)
  143.                        <---            <nak>
  144. <soh> 02 FD -data- xx  --->
  145.                        <---            <ack>
  146. <soh> 03 FC -data- xx  --->
  147.    (ack gets garbaged) <---            <ack>
  148. <soh> 03 FC -data- xx  --->            <ack>
  149. <eot>                  --->
  150.                        <---            <ack>
  151.  
  152. -------- 6. PROGRAMMING TIPS.
  153.  
  154. * The character-receive subroutine should be called with a
  155. parameter specifying the number of seconds to wait.  The
  156. receiver should first call it with a time of 10, then <nak> and
  157. try again, 10 times.
  158.   After receiving the <soh>, the receiver should call the
  159. character receive subroutine with a 1-second timeout, for the
  160. remainder of the message and the <cksum>.  Since they are sent
  161. as a continuous stream, timing out of this implies a serious
  162. like glitch that caused, say, 127 characters to be seen instead
  163. of 128.
  164.  
  165. * When the receiver wishes to <nak>, it should call a "PURGE"
  166. subroutine, to wait for the line to clear.  Recall the sender
  167. tosses any characters in its UART buffer immediately upon
  168. completing sending a block, to ensure no glitches were mis-
  169. interpreted.
  170.   The most common technique is for "PURGE" to call the
  171. character receive subroutine, specifying a 1-second timeout,
  172. and looping back to PURGE until a timeout occurs.  The <nak> is
  173. then sent, ensuring the other end will see it.
  174.  
  175. * You may wish to add code recommended by Jonh Mahr to your
  176. character receive routine - to set an error flag if the UART
  177. shows framing error, or overrun.  This will help catch a few
  178. more glitches - the most common of which is a hit in the high
  179. bits of the byte in two consecutive bytes.  The <cksum> comes
  180. out OK since counting in 1-byte produces the same result of
  181. adding 80H + 80H as with adding 00H + 00H.
  182.  cksum> comes
  183. out OK since counting in 1-byte produc